package com.qianyanglong.zhibo.client.frame;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JFrame;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.qianyanglong.zhibo.client.panel.CapturePanel;
import com.qianyanglong.zhibo.client.service.CameraService;
import com.qianyanglong.zhibo.client.service.impl.CameraServiceImpl;

public class HomeFrame extends JFrame {
	
	private static final long serialVersionUID = 1544704500794226022L;

	private static final Logger logger = LoggerFactory.getLogger(HomeFrame.class);
	
	public HomeFrame() {
		Map<String,BufferedImage> map = new HashMap<String,BufferedImage>();
		Map<String,Integer> map2 = new HashMap<String,Integer>();
		map2.put("status", 0);
		setTitle("我的直播间");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(800,600);
		setLayout(null);
		setLocationRelativeTo(null);
		CapturePanel capturePanel = new CapturePanel(map);
		capturePanel.setIgnoreRepaint(false);
		CameraService cameraService = new CameraServiceImpl(capturePanel, map2);
		capturePanel.addMouseListener(new MouseAdapter() {
			
			@Override
			public void mouseReleased(MouseEvent e) {
				Integer status = map2.get("status");
				if(status==0) {
					cameraService.start();
//					cameraService.test();
//					Thread t = new Thread(new Runnable() {
//						
//						@Override
//						public void run() {
//							cameraService.show();
//						}
//					});
//					t.start();
				} else if(status==1) {
					cameraService.pause();
				} else if(status==2) {
					cameraService.start();
				}
				
			}
			
		});
		setContentPane(capturePanel);
		setVisible(true);
	}
}
